/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.pucp.netbeans.pluggin.mda.ui;

import java.util.logging.Logger;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.openide.util.ImageUtilities;
import org.netbeans.api.settings.ConvertAsProperties;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//pe.pucp.netbeans.pluggin.mda.ui//SpringRooCommandLine//EN",
autostore = false)
public final class SpringRooCommandLineTopComponent extends TopComponent {

    private static SpringRooCommandLineTopComponent instance;
    /** path to the icon used by the component and its open action */
    static final String ICON_PATH = "pe/pucp/netbeans/pluggin/mda/ui/roo_logo.png";
    private static final String PREFERRED_ID = "SpringRooCommandLineTopComponent";

    public SpringRooCommandLineTopComponent() {
        initComponents();
        setName(NbBundle.getMessage(SpringRooCommandLineTopComponent.class, "CTL_SpringRooCommandLineTopComponent"));
        setToolTipText(NbBundle.getMessage(SpringRooCommandLineTopComponent.class, "HINT_SpringRooCommandLineTopComponent"));
        setIcon(ImageUtilities.loadImage(ICON_PATH, true));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scpTextArea = new javax.swing.JScrollPane();
        txaSpringRooOutput = new javax.swing.JTextArea();
        txtCommand = new javax.swing.JTextField();
        btnEjecutar = new javax.swing.JButton();

        txaSpringRooOutput.setColumns(20);
        txaSpringRooOutput.setRows(5);
        scpTextArea.setViewportView(txaSpringRooOutput);

        txtCommand.setText(org.openide.util.NbBundle.getMessage(SpringRooCommandLineTopComponent.class, "SpringRooCommandLineTopComponent.txtCommand.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(btnEjecutar, org.openide.util.NbBundle.getMessage(SpringRooCommandLineTopComponent.class, "SpringRooCommandLineTopComponent.btnEjecutar.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(scpTextArea, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 958, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtCommand, javax.swing.GroupLayout.DEFAULT_SIZE, 867, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(btnEjecutar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scpTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEjecutar))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEjecutar;
    private javax.swing.JScrollPane scpTextArea;
    private javax.swing.JTextArea txaSpringRooOutput;
    private javax.swing.JTextField txtCommand;
    // End of variables declaration//GEN-END:variables
    /**
     * Gets default instance. Do not use directly: reserved for *.settings files only,
     * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
     * To obtain the singleton instance, use {@link #findInstance}.
     */
    public static synchronized SpringRooCommandLineTopComponent getDefault() {
        if (instance == null) {
            instance = new SpringRooCommandLineTopComponent();
        }
        return instance;
    }

    /**
     * Obtain the SpringRooCommandLineTopComponent instance. Never call {@link #getDefault} directly!
     */
    public static synchronized SpringRooCommandLineTopComponent findInstance() {
        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
        if (win == null) {
            Logger.getLogger(SpringRooCommandLineTopComponent.class.getName()).warning(
                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
            return getDefault();
        }
        if (win instanceof SpringRooCommandLineTopComponent) {
            return (SpringRooCommandLineTopComponent) win;
        }
        Logger.getLogger(SpringRooCommandLineTopComponent.class.getName()).warning(
                "There seem to be multiple components with the '" + PREFERRED_ID
                + "' ID. That is a potential source of errors and unexpected behavior.");
        return getDefault();
    }

    @Override
    public int getPersistenceType() {
        return TopComponent.PERSISTENCE_ALWAYS;
    }

    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    Object readProperties(java.util.Properties p) {
        if (instance == null) {
            instance = this;
        }
        instance.readPropertiesImpl(p);
        return instance;
    }

    private void readPropertiesImpl(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    @Override
    protected String preferredID() {
        return PREFERRED_ID;
    }
}
